//
//  PositionCell.m
//  MyStock
//
//  Created by 刘翔 on 2025/1/3.
//

#import "PositionCell.h"
#import "UIView+JHRadarAnimation.h"

@interface PositionCell()
//@property(nonatomic,strong)FLAnimatedImage *image1;
//@property(nonatomic,strong)FLAnimatedImage *image2;


@end

@implementation PositionCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    _tagView.alignment = TTGTagCollectionAlignmentLeft;
    _tagView.manualCalculateHeight = YES;
    _tagView.userInteractionEnabled = YES;
    _tagView.delegate =self;
    
   
    
  
//    self.gifImage.contentMode = UIViewContentModeScaleAspectFill;
//    self.gifImage.animatedImage = self.image1;
//    [self.gifImage startAnimating];
    self.animationView.mj_y = HWScreenW - 35;
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setTags:(NSArray <NSString *> *)tags withSeleted:(NSString *)seletedTag {
    [_tagView removeAllTags];

    NSMutableArray *textTags = [NSMutableArray new];
    for (NSString *string in tags) {
        
        TTGTextTagStyle *style = [TTGTextTagStyle new];
        style.extraSpace = CGSizeMake(5, 5);
        style.backgroundColor = [UIColor whiteColor];
        if ([string isEqualToString:seletedTag]) {
            style.backgroundColor = Color_gree;
        }
        style.shadowColor = [UIColor clearColor];
        style.borderWidth = 1;
        style.borderColor = Color_red;
        TTGTextTagStringContent *content = [TTGTextTagStringContent contentWithText:string];
        content.textFont = [UIFont systemFontOfSize:12];
        content.textColor = Color_red;
        TTGTextTag *textTag = [TTGTextTag tagWithContent:content style:style];
        [textTags addObject:textTag];
    }
    [_tagView addTags:textTags];
    _tagView.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width - 40;
    [_tagView reload];
    [self startAnimation1];

}

- (void)setTags:(NSArray <NSString *> *)tags withHots:(NSArray *)seletedTags {
    [_tagView removeAllTags];

    NSMutableArray *textTags = [NSMutableArray new];
    for (NSString *string in tags) {
        
        TTGTextTagStyle *style = [TTGTextTagStyle new];
        style.extraSpace = CGSizeMake(5, 5);
        style.backgroundColor = [UIColor whiteColor];
        if (seletedTags.count > 0 && [seletedTags containsObject:string]) {
            style.backgroundColor = Color_gree;

        }
       
        style.shadowColor = [UIColor clearColor];
        style.borderWidth = 1;
        style.borderColor = Color_red;
        
        TTGTextTagStringContent *content = [TTGTextTagStringContent contentWithText:string];
        content.textFont = [UIFont systemFontOfSize:12];
        content.textColor = Color_red;
    
        TTGTextTag *textTag = [TTGTextTag tagWithContent:content style:style];
        [textTags addObject:textTag];
    }
    [_tagView addTags:textTags];

    // Use manual height, update preferredMaxLayoutWidth
    _tagView.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width - 40;

    [_tagView reload];
    
    
    [self startAnimation1];
}

- (void)textTagCollectionView:(TTGTextTagCollectionView *)textTagCollectionView didTapTag:(TTGTextTag *)tag atIndex:(NSUInteger)index {
    
    HotGLVC *vc = [[HotGLVC alloc] init];
    vc.glName = tag.content.getContentAttributedString.string;
    [self.viewController.navigationController pushViewController:vc animated:YES];
        
}

- (void)startAnimation1{
    [self.animationView.jh_radarAnimation reset];
    self.animationView.jh_radarAnimation.zoomRatio = 5;
    self.animationView.jh_radarAnimation.instanceCount = 3;
    self.animationView.jh_radarAnimation.instanceDelay = 0.5;
    self.animationView.jh_radarAnimation.color = [UIColor colorWithRed:255/255.0 green:85 / 255.0 blue:0 / 255.0 alpha:1];
    self.animationView.jh_radarAnimation.opacity = 0.8;
    [self.animationView.jh_radarAnimation startAnimation];
}

- (void)startAnimation2{
    [self.animationView.jh_radarAnimation reset];
    self.animationView.jh_radarAnimation.zoomRatio = 5;
    self.animationView.jh_radarAnimation.instanceCount = 3;
    self.animationView.jh_radarAnimation.instanceDelay = 0.5;
    self.animationView.jh_radarAnimation.color = [UIColor colorWithRed:255/255.0 green:0 / 255.0 blue:0 / 255.0 alpha:1];;
    self.animationView.jh_radarAnimation.opacity = 0.8;
    [self.animationView.jh_radarAnimation startAnimation];
}

- (void)stop{
    [self.animationView.jh_radarAnimation stopAnimation];
}


@end
